package com.yuanzong.wuliu.service.admin.base;

import com.yuanzong.wuliu.common.exception.BusinessException;
import com.yuanzong.wuliu.common.utils.file.FileUtils;
import com.yuanzong.wuliu.common.vo.ApiResult;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class AdminFileService {

    // 是否采用本地文件
    private static final boolean thisLocality = false;

//    public ApiResult upload(MultipartFile file) throws Exception {
//        if (file == null) {
//            throw new BusinessException("文件为空");
//        }
//        String fileSelectUrl = null;
//        if (thisLocality) {
//            fileSelectUrl = FileUtils.create(file);
//        } else {
//            fileSelectUrl = TxOssUtils.upload(file, SnowFlakeUtils.getId() + "");
//        }
//        return ApiResult.success(fileSelectUrl);
//    }

    public ApiResult uploadLocal(MultipartFile file) throws Exception {
        if (file == null) {
            throw new BusinessException("文件为空");
        }
        String fileSelectUrl = FileUtils.create(file);
        return ApiResult.success(fileSelectUrl);
    }
}
